package hu.issue.framework.web.validation;

import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

public class RequestValidation {
	private final List<Validator> validators = new LinkedList<Validator>();
	private final HttpServletRequest request;
	private final ErrorMessages messages;

	public RequestValidation(final HttpServletRequest request, final ErrorMessages messages) {
		this.request = request;
		this.messages = messages;
	}

	/**
	 * 
	 * @return true when validation succes, false when validation fails
	 */
	public boolean validate() {
		boolean ret = true;
		for (final Validator validator : this.validators) {
			ret &= validator.validate(this.request, this.messages);
		}

		return ret;
	}

	public void addValidator(final Validator validator) {
		this.validators.add(validator);
	}
}
